const TerserPlugin = require('terser-webpack-plugin')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const { merge } = require('webpack-merge')
const config = require('./webpack.config')
module.exports = merge(config, {
  mode: 'production',
  devtool: false,
  optimization: {
    runtimeChunk: true,
    usedExports: true,
    minimize: true,
    minimizer: [
      new TerserPlugin({
        extractComments: false
      })
    ],
    splitChunks: {
      chunks: 'initial',
      minSize: 0,
      minChunks: 1,
      cacheGroups: {
        defaultVendors: {
          test: /[\\/]node_modules[\\/]/,
          name: 'chunk-vendor',
          priority: -10,
          reuseExistingChunk: true
        },
        default: {
          minChunks: 2,
          priority: -20,
          name: 'chunk-'
        }
      }
    }
  },
  plugins: [
    new CompressionWebpackPlugin({
      test: /\.(css|js)$/,
      threshold: 0,
      minRatio: 0.8
    })
  ]
})